

public class PurchasesRow {
	private String accountID;
	private String purchaseNum;
	private String cName;
	private String title;
	private String ticketType;
	private String ticketPrice;
	public static boolean is_cinema = true;

	public PurchasesRow(String the_accountID, int the_purchaseNum, 
			String the_cName, String the_title, String the_ticketType, 
			int the_ticketPrice) {
		accountID = the_accountID;
		purchaseNum = String.valueOf(the_purchaseNum);
		cName = the_cName;
		title = the_title;
		ticketType = the_ticketType;
		ticketPrice = String.valueOf(the_ticketPrice);
	}

	/**
	 * Takes a string of data (returned from the database) to construct this
	 * object.
	 * @param the_data The row to be converted.
	 */
	public PurchasesRow(String the_data) {
		parseDataString(the_data);
	}

	public void set(String the_data) {
		parseDataString(the_data);
	}

	public String getAccountID()  	{ return accountID;  }
	public String getPurchaseNum()  { return purchaseNum;  }
	public String getCName() 		{ return cName; }
	public String getTitle() 		{ return title; }
	public String getTicketType() 	{ return ticketType; }
	public String getTicketPrice() 	{ return ticketPrice; }

	public String[] getDataArray() {
		String[] arr = new String[4];
		arr[0] = purchaseNum;
		arr[1] = cName;
		arr[2] = title;
		arr[3] = ticketType;
		return arr;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(purchaseNum);
		sb.append("\t");
		sb.append(cName);
		sb.append("\t");
		sb.append(title);
		sb.append("\t");
		sb.append(ticketType);
		return sb.toString();
	}


	private void parseDataString(String str) {	
		purchaseNum = str.substring(0,str.indexOf('\t')).trim();
		str = str.substring(str.indexOf('\t'),str.length()).trim();
		
		if (is_cinema) {
			accountID = str.substring(0,str.indexOf('\t')).trim();
			str = str.substring(str.indexOf('\t'),str.length()).trim();
		}
		
		if (!is_cinema) {
			cName = str.substring(0,str.indexOf('\t')).trim();
			str = str.substring(str.indexOf('\t'),str.length()).trim();
		}
		
		title = str.substring(0,str.indexOf('\t')).trim();
		str = str.substring(str.indexOf('\t'),str.length()).trim();
		ticketType = str.substring(0,str.indexOf('\t')).trim();
		ticketPrice = "$" + str.substring(str.indexOf('\t'),str.length()).trim();
		
	}
}
